/*
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 
 */

package beans;

import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import pojos.Employees;
import pojos.Expenses;

/**
 * @author A7med Kotb
 */
@Stateless
public class ExpensesFacade extends AbstractFacade<Expenses> {
    
    @PersistenceContext(unitName = "AquantimaISPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public ExpensesFacade() {
        super(Expenses.class);
    }

    public List getResultSet(Expenses expense) {
        Query query = getEntityManager().createNamedQuery("Expenses.findByExpId");
        query.setParameter("expId",expense.getExpId());
        return query.getResultList();
    }

    /**
     * List User Expenses...
     * @param employee
     * @return 
     */
    public List getUserExpenses(Employees employee) {
        Query query = getEntityManager().createNamedQuery("Expenses.findByEmployee");
        query.setParameter("employee",employee);
        List mylist=query.getResultList();
        return mylist;
    }

    /**
     * Search Expenses for user
     * @param fromDate
     * @param toDate
     * @param userMail
     * @return 
     */
    public List getUserExpenses(Date fromDate, Date toDate, Employees userMail) {
        Query query = getEntityManager().createNamedQuery("Expenses.findByEmployeeandDate");
        query.setParameter("employee",userMail);
        query.setParameter("fromDate",fromDate);
        query.setParameter("toDate",toDate);
        List mylist=query.getResultList();
        return mylist;
    }
    
    /**
     * Search Expenses for Admin
     * @param from
     * @param to
     * @return list of Expenses within the Date Range
     *
     */
    public List<Expenses> getExpenses(Date from, Date to) {
        Query query = getEntityManager().createNamedQuery("Expenses.findByExpenseDate");
        query.setParameter("fromDate", from);
        query.setParameter("toDate", to);
        return query.getResultList();
    }
}